package com.bjwl.service.impl;

import com.bjwl.dao.IpRightsMapper;
import com.bjwl.pojo.IpRights;
import com.bjwl.pojo.dto.IpRightDto;
import com.bjwl.service.IpRightsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/25 9:17
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Service
@Transactional
public class IpRightsServiceImpl implements IpRightsService {

    @Autowired
    private IpRightsMapper ipRightsMapper;

    @Override
    public boolean findIpRightByIpAndBsadmin(String ip, int id) {
        IpRights ipRights = ipRightsMapper.findIpRightByIpAndBsadmin(ip,id);
        if(ipRights != null && ipRights.getState().equals(1)){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public void addIpRight(String ip, int id, String addr) {
        IpRights ipRights = ipRightsMapper.findIpRightByIpAndBsadmin(ip,id);
        if(ipRights == null){
            ipRightsMapper.addIpRight(ip,id,addr);
        }
    }

    @Override
    public List<IpRightDto> findAll() {
       return ipRightsMapper.findAll();
    }

    @Override
    public void update(IpRights ipRights) {
        ipRightsMapper.update(ipRights);
    }
}
